/*

 */
package com.ohos.connent.bizscenecloud.biz.modular.device.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.ohos.connent.bizscenecloud.biz.modular.device.entity.BusinessDevLibFile;
import com.ohos.connent.bizscenecloud.biz.modular.device.param.*;
import com.ohos.connent.bizscenecloud.biz.modular.device.result.BizScenesUploadAuthResult;
import com.ohos.connent.bizscenecloud.biz.modular.device.service.BizScenesService;
import com.ohos.connent.bizscenecloud.common.annotation.CommonLog;
import com.ohos.connent.bizscenecloud.common.pojo.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;

/**
 * 场景库文件管理控制器
 **/
@Api(tags = "场景库文件管理控制器")
@ApiSupport(author = "OHOSCONNECT_TEAM", order = 2)
@RestController
@RequestMapping(value = "/api/v1/business/biz/scenes/sceneslib-file-manager")
@Validated
public class BizScenesController {

    @Resource
    private BizScenesService bizScenesService;

    /**
     * 获取场景库文件管理分页数据
     */
    @ApiOperationSupport(order = 1)
    @ApiOperation("获取场景库文件管理分页数据")
    @PostMapping("/page")
    public CommonResult<Page<BusinessDevLibFile>> page(@RequestBody BizScenesPageParam bizScenesPageParam) {
        return CommonResult.data(bizScenesService.page(bizScenesPageParam));
    }

    /**
     * 返回文件上传授权URL和文件id
     *
     *
     **/
    @ApiOperationSupport(order = 2)
    @ApiOperation("获取华为云文件上传授权URL和文件id")
    @CommonLog("获取华为云文件上传授权URL和文件id")
    @PostMapping("/file/getHWYunUploadAuthUrlAndFileId")
    public CommonResult<BizScenesUploadAuthResult> getHWYunUploadAuthUrlAndFileId(@RequestBody BizScenesUploadParam bizScenesUploadParam) {
        return CommonResult.data(bizScenesService.getHWYunUploadAuthUrlAndFileId(bizScenesUploadParam));
    }

    /**
     * 新增场景库文件
     */
    @ApiOperationSupport(order = 4)
    @ApiOperation("新增场景库文件")
    @CommonLog("新增场景库文件")
    @PostMapping("/add")
    public CommonResult<String> add(@RequestBody @Valid BizScenesAddParam bizScenesAddParam) {
        bizScenesService.add(bizScenesAddParam);
        return CommonResult.ok();
    }

    /**
     * 删除场景库文件：逻辑删除
     */
    @ApiOperationSupport(order = 4)
    @ApiOperation("删除场景库文件")
    @CommonLog("删除场景库文件")
    @PostMapping("/delete")
    public CommonResult<String> delete(@RequestBody @Valid BizScenesIdsParam bizScenesIdsParam) {
        bizScenesService.delete(bizScenesIdsParam);
        return CommonResult.ok();
    }


    /**
     * 获取华为云文件下载授权URL
     */
    @ApiOperationSupport(order = 5)
    @ApiOperation("获取华为云文件下载授权URL")
    @CommonLog("获取华为云文件下载授权URL")
    @PostMapping("/file/getFileDownloadAuthUrlHUAWEI")
    public CommonResult<String> getFileDownloadAuthUrlHUAWEI(@RequestBody @Valid BizScenesIdParam bizScenesIdParam) {
       return CommonResult.data(bizScenesService.getFileDownloadAuthUrlHUAWEI(bizScenesIdParam));
    }

    /**
     * 上传场景库文件
     */
    @ApiOperationSupport(order = 6)
    @ApiOperation("上传场景库文件")
    @CommonLog("上传场景库文件")
    @PostMapping("/file/upload")
    public CommonResult<String> upload(@RequestPart("file") MultipartFile file,
                                       @RequestParam @NotEmpty(message = "文件id不能为空") String fileId) {
        bizScenesService.upload(file, fileId);
        return CommonResult.ok();
    }

}
